package com.liao.kv.key;

import com.liao.kv.base.BaseDimension;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/*时间维度类*/
public class DateDimension extends BaseDimension {

    //时间维度主键
    private int id;
    //时间维度：当前通话信息所在年
    private int year;
    //时间维度：当前通话信息所在月,如果按照年来统计信息，则month为-1
    private int month;
    //时间维度：当前通话信息所在日,如果按照年来统计信息，则day为-1。
    private int day;

    public DateDimension() {
        super();
    }

    public DateDimension(int year, int month, int day) {
        super();
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int compareTo(BaseDimension o) {
        DateDimension other=(DateDimension) o;
        //先判断年是否相等
        int result=String.valueOf(year).compareTo(String.valueOf(other.year));
        if(result==0){//年不相同时
            //比较月
            result=String.valueOf(month).compareTo(String.valueOf(other.month));
        }
        if(result==0){//月不相同时
            //比较日
            result=String.valueOf(day).compareTo(String.valueOf(other.day));
        }
      return result;
    }

    public void write(DataOutput out) throws IOException {
        out.writeInt(this.id);
        out.writeInt(this.year);
        out.writeInt(this.month);
        out.writeInt(this.day);

    }

    public void readFields(DataInput in) throws IOException {
        this.id = in.readInt();
        this.year = in.readInt();
        this.month = in.readInt();
        this.day = in.readInt();
    }

    @Override
    public String toString() {
        return "DateDimension{" +
                "id=" + id +
                ", year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}
